package com.automobile.backstage.dao;

import com.automobile.backstage.domain.Sugest;
import net.sf.ehcache.util.PropertyUtil;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SugestDao {
	
	@Insert("insert into suggest(message) values(#{message})")
	void newSugest(String message);

	@Select("select * from suggest")
    @Results(id = "suggestId",value = {
	    @Result(property = "id",column = "id",id = true),
        @Result(property = "userId",column = "userId"),
        @Result(property = "title",column = "title"),
        @Result(property = "message",column = "message"),
        @Result(property = "user",column = "userId" ,one = @One(select = "com.automobile.backstage.dao.UserDao.findBySuggest",fetchType = FetchType.LAZY))
    })
    List<Sugest> findAll() throws Exception;

	@Select("select * from suggest where id = #{id}")
    @ResultMap("suggestId")
    Sugest findById(Integer id) throws Exception;

	@Delete("delete from suggest where id = #{id}")
    void del(Integer id) throws  Exception;
	
}
